package com.bdqn.util;

import org.springframework.util.StringUtils;
import redis.clients.jedis.Jedis;

import javax.servlet.http.HttpServletRequest;

public class UserUtil {

    public static String getUserName(HttpServletRequest request){
        String token = request.getHeader("token");
        //1、判断前端是否带了请求头token参数
        if (!StringUtils.isEmpty(token)) {

            //2、从redis 读取token的值，获取当前登录用户
            try (Jedis jedis = new Jedis("47.106.226.199", 6429)) {
                jedis.auth("666t01");
                return  jedis.get(token);
            }
        }
        return null;
    }
}
